﻿@using System.Web.Mvc
@using Senparc.Core.Extensions
@using Senparc.Core.Models
@model Senparc.Areas.Admin.Models.VD.Log_WebLogDateVD
@{
    ViewData["Title"] = "日志详细信息";
}
@section breadcrumbs{
    <li>
        <a href="@Url.Action("WebLogList", "Log")">系统日志列表</a>
    </li>
    <li>
        @ViewData["Title"]
    </li>
}
@section HeaderContent{
    <style type="text/css">
        .loading2-hide {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var filter_kinds = [];
        var filter_threadNames = [];
        var filter_logNames = [];
        var current_filter_kind = "all";
        var current_filter_threadName = "all";
        var current_filter_logName = "all";
        $(function () {
            //            setCurrentMenu("superadmin", "weblog");

            //            //overlay
            //            $("a[rel]").overlay();

            //类型
            $("select").filter("#filter_kind,#filter_thread,#filter_logname").click(function () {
                initFilter($(this));
            }).change(function () {
                switch ($(this).attr("id")) {
                    case "filter_kind":
                        current_filter_kind = $(this).val();
                        break;
                    case "filter_thread":
                        current_filter_threadName = $(this).val();
                        break;
                    case "filter_logname":
                        current_filter_logName = $(this).val();
                        break;
                    default:
                        break;
                }
                filter();
            });

            $("#logDetails").dialog({
                autoOpen: false,
                modal: true,
                width: "800",
                height: "530"
            });
        });

        //初始化
        function initFilter(filterSelect) {
            if (filterSelect.find("option").size() > 1) {
                return;
            }
            var trs = $("#log_table tbody tr");
            $.each(trs, function (i, item) {
                //类型
                var currentKind = $(item).find("td").eq(1).text();
                if (currentKind == "") {
                    return; //过滤最后一行
                }

                if (filter_kinds[currentKind] == null) {
                    filter_kinds[currentKind] = 0;
                    $("select#filter_kind").append("<option value='" + currentKind + "'>" + currentKind + "</option>");
                }
                else {
                    filter_kinds[currentKind]++;
                }
                $(item).attr("logkind", currentKind);

                //线程名称
                var currentThreadName = $(item).find("td").eq(2).text().replace("[", "").replace("]", "");
                if (filter_threadNames[currentThreadName] == null) {
                    filter_threadNames[currentThreadName] = 0;
                    $("select#filter_thread").append("<option value='" + currentThreadName + "'>" + currentThreadName + "</option>");
                }
                else {
                    filter_threadNames[currentThreadName]++;
                }
                $(item).attr("logthread", currentThreadName);

                //Log Name
                var currentLogName = $(item).find("td").eq(3).text();
                if (filter_logNames[currentLogName] == null) {
                    filter_logNames[currentLogName] = 0;
                    $("select#filter_logname").append("<option value='" + currentLogName + "'>" + currentLogName + "</option>");
                }
                else {
                    filter_logNames[currentLogName]++;
                }
                $(item).attr("logname", currentLogName);
            });
        }

        function filter() {
            var kind = current_filter_kind;
            var threadName = current_filter_threadName;
            var logName = current_filter_logName;

            var kindFilter = kind == "all" ? "" : ("[logkind='" + kind + "']");
            var threadFIlter = threadName == "all" ? "" : ("[logthread='" + threadName + "']");
            var logNameFilter = logName == "all" ? "" : ("[logname='" + logName + "']");

            var datarow = $("#log_table tbody tr");
            if (kind == "all" && threadName == "all" && logName == "all") {
                datarow.show();
            } else {
                var showRows = datarow.filter(kindFilter + threadFIlter + logNameFilter);
                showRows.show();
                datarow.not(showRows).hide();
            }
        }

        function viewDetail(date, pageIndex, line) {
            $("#logDetails_loading").hide();
            clearDetail();
            $.getJSON('@Url.Action("WebLogDetail", "Log")', { date: date, pageIndex: pageIndex, line: line }, function (json) {
                if (json.success) {
                    $("#logDetails_time").html(json.date);
                    $("#logDetails_time_info").html(json.msg);
                    $("#logDetails_detail").html(json.detail);

                    $("#logDetails").dialog("open");
                } else {
                    alert(json.msg);
                }
            });
        }

        function clearDetail() {
            $("#logDetails_time,#logDetails_time_info,#logDetails_detail").empty();
        }
    </script>
}
@*@using (Html.ContentBox("系统日志详情 -" + Model.CurrentDate.ToString("yyyy-MM-dd"),
   @Html.ActionLink("列表", "Index"),
   "<a href=\"#tab1\" class=\"default-tab\">详情 {0}</a>".With(Model.CurrentDate.ToString("yyyy-MM-dd"))))*@
{

    <h2></h2>
    <div id="logDetails" class="loading2-hide simple_overlay">
        <span class="loading2 loading2-hide" id="logDetails_loading"></span><strong>
            时间：<span id="logDetails_time"></span><br />
            日志信息：<span id="logDetails_time_info"></span>
        </strong><br />
        <span id="logDetails_detail"></span>
    </div>
    <p>
        @if (Model.PageIndex <= 0)
        {
            <text>显示全部</text>
        }
        else
        {
            @Html.ActionLink("显示全部", "WebLogDate", new { date = Model.CurrentDate.ToString("yyyyMMdd"), pageIndex = 0 })

        }
        @for (int i = 1; i <= Model.TotalPageCount; i++)
        {
            <text>|</text>
            if (Model.PageIndex == i)
            {
                <strong>@("第{0}页".With(i))</strong>
            }
            else
            {
                @Html.ActionLink("第{0}页".With(i), "WebLogDate", new { date = Model.CurrentDate.ToString("yyyy-MM-dd"), pageIndex = i })
            }
        }
    </p>
    <p id="filter">
        <a href="#">分类筛查</a> | 类型：
        <select id="filter_kind">
            <option value="all">全部显示</option>
        </select>
        线程名称：
        <select id="filter_thread">
            <option value="all">全部显示</option>
        </select>
        Log名称：
        <select id="filter_logname">
            <option value="all">全部显示</option>
        </select>
    </p>
    @*@Html.GridView(Model.LogList, new { id = "log_table", @class = "datatable" }, "没有日志", false,
                new GridViewItemTemplateModel<WebLog>("时间", (z, i) => z.DateTime.ToString("HH:mm:ss"), null),
                new GridViewItemTemplateModel<WebLog>("类型", (z, i) => z.Level, null),
                new GridViewItemTemplateModel<WebLog>("线程名", (z, i) => z.ThreadName, null),
                new GridViewItemTemplateModel<WebLog>("Logger名", (z, i) => z.LoggerName, null),
                new GridViewItemTemplateModel<WebLog>("信息", (z, i) => z.Message, null),
                new GridViewItemTemplateModel<WebLog>("查看", (z, i) => "<a href=\"javascript:void(0);\" rel=\"#logDetails\" onclick=\"viewDetail('{0}',{1},{2})\">查看</a>".With(Model.CurrentDate.ToString("yyyy-MM-dd"), z.PageIndex, z.Line), new { style = "width:35px;" })
        )*@
}